package org.jjche.file.modules.file.api;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.jjche.common.enums.LogCategoryType;
import org.jjche.common.enums.LogType;
import org.jjche.core.base.BaseController;
import org.jjche.file.constant.FileApiVersion;
import org.jjche.file.modules.file.api.vo.FileVO;
import org.jjche.log.biz.starter.annotation.LogRecord;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 件 控制器,feign
 * </p>
 *
 * @author miaoyj
 * @since 2024-07-15
 */
@Api(tags = "文件-对内")
@ApiSupport(order = 1, author = "miaoyj")
@RestController
@RequestMapping("/internal")
@RequiredArgsConstructor
public class FileApiController extends BaseController {
    private final FileApi fileApi;

    @ApiOperation("上传文件")
    @PostMapping("upload")
    public FileVO upload(@RequestPart("file") MultipartFile file) {
        return fileApi.upload(file);
    }

    @ApiOperation("上传图片")
    @PostMapping("upload-image")
    public FileVO uploadImage(@RequestPart("file") MultipartFile file) {
        return fileApi.uploadImage(file);
    }

    @LogRecord(
            value = "多选删除", category = LogCategoryType.MANAGER,
            type = LogType.DELETE, module = FileApiVersion.MODULE_FILE
    )
    @DeleteMapping
    @ApiOperation("多选删除")
    @Transactional(rollbackFor = Exception.class)
    public void delete(@RequestBody List<String> ids) {
        fileApi.delete(ids);
    }

    @LogRecord(
            value = "删除", category = LogCategoryType.MANAGER,
            type = LogType.DELETE, module = FileApiVersion.MODULE_FILE
    )
    @DeleteMapping("urls")
    @ApiOperation("删除-根据文件地址")
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteUrls(@RequestBody Set<String> urls) {
        return fileApi.deleteUrls(urls);
    }
}
